/*
 * ConnectButtonListener.cpp
 *
 *  Created on: Oct 24, 2011
 *      Author: gonzalo
 */

#include "ConnectButtonListener.h"

ConnectButtonListener::ConnectButtonListener(Textbox* userName, Textbox* host,Textbox* port) {
	this->userName = userName;
	this->host = host;
	this->port = port;
}

ConnectButtonListener::~ConnectButtonListener() {
}

void ConnectButtonListener::execute() {
	std::string user = this->userName->getInput();
	std::string host = this->host->getInput();
	std::string port = this->port->getInput();

	if ((host.length()!=0)&&(user.length()!=0)&&(port.length()!=0)){
		pushEventsToOpenEditSceneWindow(user, host,port);
	}else{
		Logger::debug("ConnectButtonListener","execute","No ha elegido su nombre de jugador o su host ");
	}
}

void ConnectButtonListener::pushEventsToOpenEditSceneWindow(std::string user,std::string host,std::string port) {

	SDL_Event event1;
	event1.type = SDL_USEREVENT;
	event1.user.code = CONNECT;
	event1.user.data1 = new std::string(host + ":" + port);
	event1.user.data2 = new std::string(user);
	SDL_PushEvent(&event1);
}

